package top.callback.inf.beautyleaf.server;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

/**
 * 启动类
 *
 * @author Pengyu Gan
 * CreateDate 2021/3/25
 */
@SpringBootApplication
@MapperScan(basePackages = {"top.callback.inf.beautyleaf.server.dao"})
@EnableTransactionManagement
public class BeautyLeafServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(BeautyLeafServerApplication.class, args);
    }

    /**
     * 强制 hikari 在项目启动时初始化数据库连接池
     * @param dataSource 数据源
     * @return {@link ApplicationRunner}
     */
    @Bean
    public ApplicationRunner runner(DataSource dataSource) {
        return args -> dataSource.getConnection();
    }

    @Bean
    public OpenAPI springShopOpenAPI() {
        return new OpenAPI()
                .info(new Info().title("BeautyLeaf API")
                .description("BeautyLeaf Application API Manual")
                .version("v1.0"));
    }

}
